package com.JinYuan.service.impl;

import com.JinYuan.dao.UserDao;
import com.JinYuan.pojo.User;
import com.JinYuan.service.UserService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author 金园
 * @create 2022/5/11
 * @Description
 * @className userServiceImpl
 * @packageName com.JinYuan.service.impl
 */
@Service
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true)
public class UserServiceImpl implements UserService {
    @Autowired
    UserDao userDao;
    @Override
    public User findById(Integer id) {
        return userDao.findById(id);
    }

    @Override
    public PageInfo<User> findByPage(Integer pageNum, Integer pageSize) {
        //使用分页插件
        //开始分页
        PageHelper.startPage(pageNum,pageSize);
        //查询所有
        List<User> userList = userDao.findByAll();
        //创建PageInfo对象
        PageInfo<User> pageInfo = new PageInfo<>(userList);
        return pageInfo;
    }
}
